package com.lanlian.cayman.adapter;

import android.graphics.Color;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lanlian.cayman.R;
import com.lanlian.cayman.utils.MResUtil;
import com.lanlian.commonlib.bean.DealDetailsInfo;
import com.lanlian.utillib.DateUtils;

import java.text.NumberFormat;
import java.util.Date;
import java.util.List;

/**
 * <pre>
 *     author : huxiaobo
 *     e-mail : huxiaobo@xlanlian.com
 *     date   : 2018/8/15 16:55
 *     desc   : 成交明细Adapter
 *     version: 1.0
 * </pre>
 */
public class TradeDetailsDealAdapter extends BaseQuickAdapter<DealDetailsInfo, BaseViewHolder> {

    public TradeDetailsDealAdapter(int layoutResId, @Nullable List<DealDetailsInfo> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, DealDetailsInfo item) {
        helper.setBackgroundColor(R.id.lay_position, (helper.getLayoutPosition() + 1) % 2 == 0 ?
                mContext.getResources().getColor(R.color.color_bg_text_view_style2) :
                mContext.getResources().getColor(R.color.color_bg_text_view_style3));
        Date date = DateUtils.StringToDate(item.getdDatetime());
        String time = DateUtils.DateToString(date, "yyyy-MM-dd\nHH:mm:ss");
        helper.setText(R.id.tv_contract_name, item.getContractName())
                .setText(R.id.tv_order_no, item.getlDealNo().toString())
                .setText(R.id.tv_direction, "1".equals(item.getcOrderDirection()) ? "买" : "卖")
                .setText(R.id.tv_currency_type, item.getCurrency())
                .setText(R.id.tv_order_amount, item.getlDealAmount().toString())
                .setText(R.id.tv_order_price, item.getEnDealPrice().toString())
                .setText(R.id.tv_fee, NumberFormat.getInstance().format(item.getEnFeeTotal()))
                .setText(R.id.tv_time, time);
        if ("1".equals(item.getcOrderDirection())) {
            helper.setTextColor(R.id.tv_direction, mContext.getResources().getColor(R.color.color_T7));
        } else {
            helper.setTextColor(R.id.tv_direction, mContext.getResources().getColor(R.color.color_T8));
        }
        if (item.getEnClosedProfit() > 0) {
            helper.setText(R.id.tv_profit_loss, String.format("+%.2f", item.getEnClosedProfit()));
            helper.setTextColor(R.id.tv_profit_loss, MResUtil.getUpColor());
        } else if (item.getEnClosedProfit() < 0) {
            helper.setText(R.id.tv_profit_loss, String.format("%.2f", item.getEnClosedProfit()));
            helper.setTextColor(R.id.tv_profit_loss, MResUtil.getDownColor());
        } else {
            helper.setText(R.id.tv_profit_loss, String.format("%.2f", item.getEnClosedProfit()));
            helper.setTextColor(R.id.tv_profit_loss, Color.parseColor("#8893B0"));
        }
    }

}
